import { ref } from 'vue'
import { defineStore } from 'pinia'
import { getLoginUserUsingGet } from '@/api/userController.ts'

export const useLoginUserState = defineStore('loginUser', () => {
  const loginUser = ref<API.LoginUserVO>({
    username: '未登录',
  })

  function setLoginUser(user: API.LoginUserVO) {
    loginUser.value = user
  }

  async function getLoginUser() {
    // 获取当前登录用户
    const res = await getLoginUserUsingGet()
    loginUser.value = res.data
  }

  return { loginUser, setLoginUser, getLoginUser }
})
